import 'package:flutter/material.dart';
import 'package:gzmall_app/common/color_common.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:gzmall_app/mine/order_list_widget.dart';

class OrderPage extends StatefulWidget {
  int curIndex = 0;
  OrderPage({this.curIndex});

  @override
  State<StatefulWidget> createState() {
    return OrderPageState(curIndex: curIndex);
  }
}

class OrderPageState extends State<OrderPage> with TickerProviderStateMixin {
  TabController _tabController;
  int curIndex = 0;

  OrderPageState({this.curIndex});

  @override
  Widget build(BuildContext context) {
    _tabController =
        TabController(initialIndex: curIndex ?? 0, length: 6, vsync: this);
    _tabController.addListener(() {
      curIndex = _tabController.index;
    });
    return Scaffold(
      appBar: _createAppBar(),
      body: Column(
        children: <Widget>[
          Container(
            color: Colors.white,
            height: 48.0,
            child: TabBar(
              controller: _tabController,
              labelColor: ColorCommon.primaryColor,
              isScrollable: true,
              unselectedLabelColor: ColorCommon.grey6,
              tabs: <Widget>[
                Tab(text: "全部"),
                Tab(text: "待付款"),
                Tab(text: "待发货"),
                Tab(text: "待收货"),
                Tab(text: "评价"),
                Tab(text: "退款退货"),
              ],
            ),
          ),
          Expanded(
            child: Container(
              margin: const EdgeInsets.only(top: 10.0),
              child: TabBarView(
                controller: _tabController,
                children: <Widget>[
                  OrderListWidget(""),
                  OrderListWidget("pending"),
                  OrderListWidget("checkouted"),
                  OrderListWidget("sent"),
                  OrderListWidget("completed"),
                  OrderListWidget("after_sale"),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  _createAppBar() {
    return AppBar(
      elevation: 0.0,
      title: Text("我的订单"),
      centerTitle: true,
      leading: IconButton(
        icon: Icon(Icons.arrow_back_ios),
        onPressed: () {
          Navigator.of(context).pop();
        },
      ),
      actions: <Widget>[],
    );
  }
}
